package com.itheima.tanhua.controller;

import com.itheima.tanhua.Dto.PageResult;
import com.itheima.tanhua.service.FreezeService;
import com.itheima.tanhua.service.UserService;
import com.itheima.tanhua.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author maorf
 * @version 1.0
 */
@RestController
@RequestMapping("manage")
public class UserController {
    @Autowired
    private FreezeService freezeService;
    @Autowired
    private UserService userService;

    //冻结用户
    @PostMapping("users/freeze")
    public ResponseEntity freeze(@RequestBody Map map){
        freezeService.freeze(map);
        return ResponseEntity.ok("操作成功");
    }

    //解冻用户
    @PostMapping("users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map map){
        freezeService.unfreeze(map);
        return ResponseEntity.ok("操作成功");
    }


    @GetMapping("users")
    public ResponseEntity list(Integer pagesize,Integer page,Long id,String nickname,String city){
        PageResult pageResult = userService.list(page,pagesize,id,nickname,city);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("users/{userID}")
    public ResponseEntity findById(@PathVariable Long userID){
        UserInfoVo userInfoVo = userService.findById(userID);
        return ResponseEntity.ok(userInfoVo);
    }

}
